package com.wy.controller.wy;

import com.wy.model.sys.PageResult;
import com.wy.model.sys.ParkingEntity;
import com.wy.service.wy.ParkingService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/parkings")
public class ParkingController {
    private Logger logger = LoggerFactory.getLogger(ParkController.class);
    @Resource
    private ParkingService parkingService;
    @GetMapping("")
    public PageResult parkList(@RequestParam(value = "pageSize",required = false) int pageSize,
                               @RequestParam(value = "page",required = false)int page,
                               @RequestParam(value = "type",required = false)String type,
                               @RequestParam(value = "status",required = false)String status,
                               @RequestParam(value = "residenceId",required = false)String residenceId,
                               @RequestParam(value = "parkId",required = false) String parkId){
        PageResult pageResult = new PageResult();
        pageResult.setData(parkingService.parkingList(pageSize,page*pageSize,type,status,residenceId,parkId));
        pageResult.setTotalCount(parkingService.parkingSize(pageSize,page*pageSize,type,status,residenceId,parkId));
        return pageResult;
    }

    @PostMapping("/parking")
    public ParkingEntity insertParking(@RequestBody ParkingEntity parkingEntity){
        parkingService.insertParking(parkingEntity);
        logger.debug("the method ending");
        return parkingEntity;
    }

    @PutMapping("{id}")
    public ParkingEntity updateParking(@RequestBody ParkingEntity parkingEntity){
        parkingService.updateParking(parkingEntity);
        return parkingEntity;
    }

    @DeleteMapping("/del")
    public void updateParking(@RequestBody List<String> groupId){
       parkingService.deleteParking(groupId);
    }

}
